<?php

namespace app\api\service;

use app\common\model\OrderItemAttribute;
use think\Log;

class OrderItemAttributeService extends BaseService
{
    public function submit($orderId, $atrworkId, $orderItemId, $matKey, $pmatKey, $productData, $fbxData, $position, $rotation, $proportion)
    {
        $orderItemAttribute = new OrderItemAttribute();
        $data = [
            'order_id'     => $orderId,
            'atrwork_id'   => $atrworkId,
            'item_id'      => $orderItemId,
            'mat_key'      => $matKey,
            'pmat_key'     => $pmatKey,
            'product_data' => $productData,
            'fbx_data'     => $fbxData,
            'position'     => json_encode($position),
            'rotation'     => json_encode($rotation),
            'proportion'   => $proportion,
        ];

        $result = $orderItemAttribute->data($data)->save();
        if (empty($result)) {
            $this->setMsg('订单项属性写入失败！');
            Log::write('订单项属性写入失败！' . $result, 'error');
            return false;
        }
        $orderItemAttribute['product'] = json_decode($productData, true);
        unset($orderItemAttribute['product_data']);
        $orderItemAttribute['fbx'] = json_decode($fbxData, true);
        unset($orderItemAttribute['fbx_data']);

        return $orderItemAttribute;

    }
}